<? startScript('jquery, jquery.tablednd'); ?><script type="text/javascript">

jQuery(function($) {
	var d = {l01:<?=$DATA['component']['id']?>};

	$("#objects").tableDnD({
	    onDragClass: "dragging",
	    onDrop: function(table, row) {
			$.post("sort-manual/", {order:$(table).tableDnDSerialize(), l01:d.l01});
	    },
		dragHandle: "dragHandle"
	});
	
	$("#objects .object").hover(function() {
          $(this).addClass('showDragHandle');
	    }, function() {
          $(this).removeClass('showDragHandle');
	    }
	);
	
	$("#objects .object a.button").click(function() {
		var self = $(this), href = self.attr("href"), parent = self.parents(".object"), id = parent.attr("id").substr(4), title = self.attr("title").match(/(«.*»)/)[0], attr = parent.find("input.attr");

		if (self.hasClass('visible')) {
			$.post(href, d);
			self.removeClass('visible').addClass('hidden').attr("title", "показать " + title).attr("href", href.replace("hide", "show"));
			attr.val(attr.val() & !1);
			return false;
		} else

		if (self.hasClass('hidden')) {
			$.post(href, d);
			self.removeClass('hidden').addClass('visible').attr("title", "скрыть " + title).attr("href", href.replace("show", "hide"));
			attr.val(attr.val() | 1);
			return false;
		} else

		if (self.hasClass('kill')) {
			if (confirm('Are you sure you want to kill ' + title + '?')) {
				$.post(href, d);
				parent.remove();
			}
			return false;
		}

		return true;
	});
	
});

</script><? endScript(); ?>

<div>

	<h3><?=t('Add string', 'cpn')?></h3>
	
	<form action="" method="post">
		<p><label><?=t('Name', 'cpn')?><br />
			<input type="text" name="title" class="wide" /></label>
			
			<input type="submit" name="create_object" value="<?=ht('Add', 'cpn')?>" /></p>
	</form>
	
	<? if (sizeof($d = dat('objects'))) { 
	
		?><table class="adm dnd" id="objects"><thead><tr class="nodrag nodrop">
		<td><?=t('Edit', 'cpn')?></td><td></td><td><?=t('Name', 'cpn')?></td></tr></thead><tbody><?
	
		foreach($d as $a) {
			?><tr id="obj-<?=$a[id]?>" class="object">
				<td>
					<? if ($a['attr'] & AA_VISIBLE) { ?>
						<a title="<?=ht('Disable «!name»', 'cpn', array('!name' => $a['name']))?>" class="button visible" href="hide-<?=$a[id]?>/"><span>Disable</span></a>
					<? } else { ?>
						<a title="<?=ht('Enable «!name»', 'cpn', array('!name' => $a['name']))?>" class="button hidden" href="show-<?=$a[id]?>/"><span>Enable</span></a>
					<? } ?>
					<a title="<?=ht('Edit «!name»', 'cpn', array('!name' => $a['name']))?>" class="button edit" href="edit-<?=$a[id]?>/"><span>Edit</span></a>
	
					<a title="<?=ht('Kill «!name»', 'cpn', array('!name' => $a['name']))?>" class="button kill" href="delete-<?=$a[id]?>/"><span>Kill</span></a>			
				</td>
				<td class="dragHandle"><input type="hidden" class="attr" name="attr[<?=$a['id']?>]" value="<?=$a['attr']?>" /></td>
				<td><a href="edit-<?=$a['id']?>/" title="<?=ht('Edit «!name»', 'cpn', array('!name' => $a['name']))?>"><?=$a['name']?></a></td>
	
			  </tr>
			<?
		}
	
		?></tbody></table><?
	
	} else {
	
		?><?=t('No strings yet.', 'cpn')?><?
	
	} ?>
	
</div>